package com.example.qxfw.dlqx.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.zy.MaxPowerLoad;
import com.example.qxfw.dlqx.mapper.MaxPowerLoadMapper;
import com.example.qxfw.dlqx.service.MaxPowerLoadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class MaxPowerLoadServiceImpl implements MaxPowerLoadService {

    @Autowired
    private MaxPowerLoadMapper maxPowerLoadMapper;

    @Override
    public List<MaxPowerLoad> getMaxTime() {
        return maxPowerLoadMapper.selectList(Wrappers.<MaxPowerLoad>lambdaQuery()
                .orderByDesc(MaxPowerLoad::getDatechar)
                .last("limit 1"));
    }

    @Override
    public List<MaxPowerLoad> listByDateChar(String dateChar) {
        return maxPowerLoadMapper.selectList(Wrappers.<MaxPowerLoad>lambdaQuery()
                .eq(MaxPowerLoad::getDatechar, Timestamp.valueOf(dateChar)));
    }

    @Override
    public List<MaxPowerLoad> listByParams(String dateChar1, String dateChar2) {
        return maxPowerLoadMapper.selectList(Wrappers.<MaxPowerLoad>lambdaQuery()
                .between(MaxPowerLoad::getDatechar,Timestamp.valueOf(dateChar1),Timestamp.valueOf(dateChar2))
                .orderByAsc(MaxPowerLoad::getDatechar));
    }
}
